import request from '@/utils/request'

// 获取统计数据
export function getStatistics() {
  return request({
    url: '/admin/statistics',
    method: 'get'
  })
}

// 获取最新订单
export function getLatestOrders() {
  return request({
    url: '/admin/orders/latest',
    method: 'get'
  })
}

// 获取最新留言
export function getLatestMessages() {
  return request({
    url: '/admin/messages/latest',
    method: 'get'
  })
}

// 用户管理
export function getUserList(params) {
  return request({
    url: '/admin/users',
    method: 'get',
    params
  })
}

export function updateUser(id, data) {
  return request({
    url: `/admin/users/${id}`,
    method: 'put',
    data
  })
}

export function resetUserPassword(id, password) {
  return request({
    url: `/admin/users/${id}/password`,
    method: 'put',
    data: { password }
  })
}

export function toggleUserStatus(id) {
  return request({
    url: `/admin/users/${id}/status`,
    method: 'put'
  })
}

// 商品管理
export function getProductList(params) {
  return request({
    url: '/admin/products',
    method: 'get',
    params
  })
}

export function getCategories() {
  return request({
    url: '/admin/products/categories',
    method: 'get'
  })
}

export function addProduct(data) {
  return request({
    url: '/admin/products',
    method: 'post',
    data
  })
}

export function updateProduct(id, data) {
  return request({
    url: `/admin/products/${id}`,
    method: 'put',
    data
  })
}

export function deleteProduct(id) {
  return request({
    url: `/admin/products/${id}`,
    method: 'delete'
  })
}

export function toggleProductStatus(id) {
  return request({
    url: `/admin/products/${id}/status`,
    method: 'put'
  })
}

// 切换商品推荐状态
export function toggleProductRecommended(id, recommended) {
  return request({
    url: `/admin/products/${id}/recommended`,
    method: 'put',
    data: { recommended }
  })
}

// 订单管理
export function getOrderList(params) {
  return request({
    url: '/admin/orders',
    method: 'get',
    params
  })
}

export function getOrderDetails(id) {
  return request({
    url: `/admin/orders/${id}`,
    method: 'get'
  })
}

export function updateOrderAddress(id, address) {
  return request({
    url: `/admin/orders/${id}/address`,
    method: 'put',
    data: { address }
  })
}

export function updateOrderStatus(id, status) {
  return request({
    url: `/admin/orders/${id}/status`,
    method: 'put',
    data: { orderStatus: status }
  })
}

export function shipOrder(id, shippingMethod) {
  return request({
    url: `/admin/orders/${id}/ship`,
    method: 'put',
    data: { shippingMethod }
  })
}

export function cancelOrder(id) {
  return request({
    url: `/admin/orders/${id}/cancel`,
    method: 'put'
  })
}

// 留言管理
export function getMessageList(params) {
  return request({
    url: '/admin/messages',
    method: 'get',
    params
  })
}

export function getMessageDetail(id) {
  return request({
    url: `/admin/messages/${id}`,
    method: 'get'
  })
}

export function replyMessage(id, reply) {
  return request({
    url: `/admin/messages/${id}/reply`,
    method: 'put',
    data: { reply }
  })
}

export function deleteMessage(id) {
  return request({
    url: `/admin/messages/${id}`,
    method: 'delete'
  })
} 